require(["./config"], () => {
    require(["template","url","header","footer","main","fly"], (template,url) =>{
        require(["./libs/utils/utils"], () => {
            class login {
                constructor () {
                   this.loginHr()
                }
                loginHr () {
                    // var username = document.querySelector('#username').value
                    // var password = document.querySelector('#password').value
                    
                    this.ways();
                    $("form").submit( function () {
                        return false;
                      } );
                     
                }
                ways (){
                    $("button").on("click", (e) => {
                        var username = document.querySelector('#username').value
                        var password = document.querySelector('#password').value
                        let userList = localStorage.getItem('userList')
                        if (userList) {
                            console.log(utils)
                            userList = JSON.parse(userList)
                            var isExist = userList.some(user => {
                                return user.username === username && user.password === password
                            })
                            if (isExist) {
                                utils.setCookie('loginUser', username)
                                alert('登录成功，即将回到首页')
                                window.open('/')
                            } else {
                                alert('用户名或者密码错误')
                            }
                        } else {
                            alert('请先注册')
                            location.open('/html/register.html')
                        } 
                    })
                }
            }
            new login()
        })
    })
})